package com.xjk.encryp;

import java.security.MessageDigest;

public class ShaEncrypt{

    /**
     * 对字符串进行sha-256摘要
     * @param data
     * @return
     * @throws Exception
     */
    public static byte[] encryptSha256(String data) throws Exception{
        return encryptSha256(data.getBytes("UTF-8"));
    }

    /**
     * 对字节流进行sha-256摘要
     * @param data
     * @return
     * @throws Exception
     */
    public static byte[] encryptSha256(byte[] data) throws Exception{
        byte[] bytes = null;
        MessageDigest sha = MessageDigest.getInstance("SHA-256");
        sha.update(data);
        bytes = sha.digest();
        return bytes;
    }
}
